package cn.edu.xust.controller;

import cn.edu.xust.communication.server.CommonOp;
import cn.edu.xust.entity.*;
import cn.edu.xust.communication.model.Result;
import cn.edu.xust.communication.remote.AmmeterRemoteReader;
import cn.edu.xust.communication.server.NettyServer;
import cn.edu.xust.configuration.exception.Default200Exception;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author ：huangxin
 * @modified ：
 * @since ：2020/03/28 17:25
 */

@Slf4j
@RestController()
@RequestMapping("/elec")
public class AmmeterController {

    @Autowired
    private AmmeterRemoteReader ammeterRemoteReader;
 


    @ResponseBody
    @RequestMapping(value = "/test/{ammeterId}")
    public List<AmmeterParameterEntity> controller(@PathVariable(value = "ammeterId") String ammeterId) {
        List<String> list = new ArrayList<>();
        list.add(ammeterId);
        return ammeterRemoteReader.realTelemetry(list);
    }

    @ResponseBody
    @RequestMapping(value = "/cmd")
    public Result cmd(@RequestBody JSONObject jsonObject) throws Default200Exception {

        String cmd = jsonObject.getString("cmd");
        String ip = jsonObject.getString("ip");
        return CommonOp.writeCommand(ip, cmd, UUID.randomUUID().toString());
    }



}
